﻿package mortal.game.resource.tableConfig
{
    import Message.DB.Tables.*;
    import com.gengine.resource.*;
    import flash.utils.*;
    import mortal.game.view.common.*;

    public class GuildBuildingConfig extends Object
    {
        private var _dic:Dictionary;
        private static var _instance:GuildBuildingConfig;

        public function GuildBuildingConfig()
        {
            if (_instance != null)
            {
                throw new Error("GuildBuildingConfig 单例 ");
            }
            this.init();
            return;
        }// end function

        public function init() : void
        {
            var _loc_1:* = ConfigManager.instance.getJSONByFileName("t_guild_structure_config.json");
            this.write(_loc_1);
            return;
        }// end function

        private function write(param1:Object) : void
        {
            var _loc_2:TGuildStructureConfig = null;
            var _loc_3:Object = null;
            for each (_loc_3 in param1)
            {
                
                _loc_2 = new TGuildStructureConfig();
                ClassTypesUtil.copyValue(_loc_2, _loc_3);
                if (!this._dic)
                {
                    this._dic = new Dictionary();
                }
                if (!this._dic.hasOwnProperty(_loc_2.guildLevel))
                {
                    this._dic[_loc_2.guildLevel] = new Dictionary();
                }
                this._dic[_loc_2.guildLevel][_loc_2.structureType] = _loc_2;
            }
            return;
        }// end function

        public function getAllBuildingList(param1:int = 1) : Dictionary
        {
            return this._dic[param1];
        }// end function

        public function getOpenBuildingList(param1:int) : Dictionary
        {
            var _loc_4:* = undefined;
            var _loc_2:* = new Dictionary();
            var _loc_3:* = this.getAllBuildingList(param1);
            for (_loc_4 in _loc_3)
            {
                
                if (_loc_3[_loc_4].structureLevel > 0)
                {
                    _loc_2[_loc_4] = _loc_3[_loc_4];
                }
            }
            return _loc_2;
        }// end function

        public function getInfoByBuildingType(param1:int, param2:int) : TGuildStructureConfig
        {
            if (param1 == 0)
            {
                return null;
            }
            return this._dic[param1][param2];
        }// end function

        public function getNewBuilding(param1:int) : Dictionary
        {
            var _loc_5:TGuildStructureConfig = null;
            if (param1 == 1)
            {
                return this.getOpenBuildingList(param1);
            }
            var _loc_2:* = new Dictionary();
            var _loc_3:* = this.getOpenBuildingList(param1);
            var _loc_4:* = this.getAllBuildingList((param1 - 1));
            for each (_loc_5 in _loc_3)
            {
                
                if (_loc_4[_loc_5.structureType].structureLevel < _loc_5.structureLevel)
                {
                    _loc_2[_loc_5.structureType] = _loc_5;
                }
            }
            return _loc_2;
        }// end function

        public function getNextBuildingLvNeedGuildLv(param1:int, param2:int) : int
        {
            var _loc_3:* = param1;
            var _loc_4:* = this.getAllBuildingList(_loc_3);
            var _loc_5:* = _loc_4[param2].structureLevel;
            while (_loc_4 != null)
            {
                
                if (_loc_4[param2] && _loc_4[param2].structureLevel > _loc_5)
                {
                    return _loc_4[param2].guildLevel;
                }
                _loc_3++;
                _loc_4 = this.getAllBuildingList(_loc_3);
            }
            return -1;
        }// end function

        public function getNextBuildingLvNeedGuildLv2(param1:int, param2:int, param3:int) : int
        {
            var _loc_4:* = param1;
            var _loc_5:* = this.getAllBuildingList(_loc_4);
            while (_loc_5 != null)
            {
                
                if (_loc_5[param2] && _loc_5[param2].structureLevel > param3)
                {
                    return _loc_5[param2].guildLevel;
                }
                _loc_4++;
                _loc_5 = this.getAllBuildingList(_loc_4);
            }
            return -1;
        }// end function

        public function getDic() : Dictionary
        {
            return this._dic;
        }// end function

        public static function get instance() : GuildBuildingConfig
        {
            if (_instance == null)
            {
                _instance = new GuildBuildingConfig;
            }
            return _instance;
        }// end function

    }
}
